package com.jasonchoi.security.entity;

import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.List;

/**
 * null
 */
@Data
@Accessors(chain = true)
@Entity
@Table(name = "role")
public class Role implements Serializable {

	/**
	 * 主键
	 * default value: null
	 */
	@Id
	@Column(name = "id", nullable = false, length = 20)
	private Long id;

	/**
	 * null
	 * default value: null
	 */
	@Column(name = "name", nullable = true, length = 255)
	private String name;

	@ManyToMany(mappedBy = "roleList")
	@ToString.Exclude
	private List<User> userList;

	@ManyToMany
	@ToString.Exclude //同时使用lambok+jpaLazyload 要去掉关联字段 不然会循环引用
	@JoinTable(name = "role_permission",
			joinColumns = @JoinColumn(name = "role_id"),
			inverseJoinColumns = @JoinColumn(name = "permission_id"))
	private List<Permission> permissionList;
}
